﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AdminForm.ascx.cs" Inherits="Phong_CTSV.AdminForm" %>
<% 
    bool hasRowsHeader = form.Has_rows;
%>
<div class="title">
    <h1>
        <% Response.Write(form.Decription); %></h1>
</div>
<div class="scroll">
    <table class="clientForm">
        <thead>
            <tr>
                <%  if (form.IsSum)
                    { %>
                <td rowspan="2">
                    Trường
                </td>
                <%  }
                    int temp = 0;
                    // PARENT COLUMN HEADER GENERATE
                    int index;
                    index = form.Has_rows == true ? 1 : 0;
                    index = form.IsSum == true ? index : 0;
                    for (; index < ColumnsHeaderList.Count; index++)
                    {
                        if (ColumnsHeaderList[index].Parent_id == 0)
                        {
                            int child = 0;
                            foreach (Phong_CTSV.Columns_Header childHeader in ColumnsHeaderList)
                            {
                                if (childHeader.Parent_id == ColumnsHeaderList[index].ID)
                                {
                                    child++;
                                }
                            }

                         
                            {%>
                <td <%  if (child==0) {Response.Write("rowspan=2");} else {Response.Write("colspan="+child);} %>
                    class="<% if (index%2==0) { Response.Write("even");} else { Response.Write("odd");} %>">
                    <%Response.Write(ColumnsHeaderList[index].Name);%>
                </td>
                <%}

                        }
                    }
                %>
            </tr>
            <tr>
                <%
                    temp = 0;
                    //CHILD COLUMN HEADER
                    foreach (Phong_CTSV.Columns_Header ch in ColumnsHeaderList)
                    {
                        if (ch.Parent_id != 0)
                        {
                %>
                <td class="<% if (temp%2==0) { Response.Write("sub-even"); } else { Response.Write("sub-odd");} %>">
                    <%Response.Write(ch.Name); %>
                </td>
                <%      
                    }//if
                        temp++;
                    } //foreach
                %>
            </tr>
        </thead>
        <tbody>
            <%
                // ROW HEADER GENERATE
                int rowIndex = (form.IsSum) ?1:0;
                int maxRow = (form.IsSum) ? listUni.Count : NumRow;
                for (int i = rowIndex; i < maxRow; i++)
                {
            %>
            <tr class='<% if (temp%2==0) { Response.Write("even");} else { Response.Write("odd");} %>'>
                <td>
                    <%if (form.IsSum)
                          Response.Write(listUni[i].Name);
                      else
                          Response.Write(RowsHeaderList[i].Name); %>
                </td>
                <% 

                    for (int j = 0; j < NumColumn; j++)
                    {
                %>
                <td>
                    <%if(form.IsSum)
                          Response.Write(DataTable[i - 1, j].Value); 
                      else
                          Response.Write(DataTable[i, j].Value);  %>
                </td>
                <%
               
                    }
                %>
            </tr>
            <%
rowIndex++;
temp++;
                }  
           
            %>
        </tbody>
        <% if (form.IsSum == true)
           { %>
        <tfoot>
            <tr>
                <td>
                    TỔNG
                </td>
                <%for (int i = 0; i < NumColumn; i++)
                  {%>
                <td>
                    <%Response.Write(Sum[i].Value); %>
                </td>
                <%} %>
            </tr>
        </tfoot>
        <%} %>
    </table>
</div>
<asp:Button ID="Download" runat="server"  CssClass="button"  Text="Tải về" OnClick="Download_Download" />